package com.party.admin.web.controller.system;

import com.party.admin.biz.system.MemberBizService;
import com.party.admin.web.dto.AjaxResult;
import com.party.common.utils.StringUtils;
import com.party.core.model.member.PackageCount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author： yifeng
 * @description： 套餐使用控制
 * @date：Created in  2017/12/05 下午 18:20
 **/
@Controller
@RequestMapping("/member/packageCount")
public class PackageCountController {
    @Autowired
    private MemberBizService memberBizService;

    /**
     * 充值
     *
     * @param packageCount
     * @return
     */
    @ResponseBody
    @RequestMapping("recharge")
    public AjaxResult recharge(PackageCount packageCount) {
        if (StringUtils.isEmpty(packageCount.getMemberId())) {
            return AjaxResult.error("用户不能为空");
        }
        if (StringUtils.isEmpty(packageCount.getType())) {
            return AjaxResult.error("充值类型不能为空");
        }
        if (packageCount.getQuantity() == null || packageCount.getQuantity() == 0) {
            return AjaxResult.error("充值数量异常");
        }
        try {
            memberBizService.savePackageCountBiz(packageCount);
            return AjaxResult.success();
        } catch (Exception e) {
            return AjaxResult.error("充值异常");
        }
    }

    /**
     * 保存配置
     *
     * @param packageCount
     * @return
     */
    @ResponseBody
    @RequestMapping("saveSettings")
    public AjaxResult savePackageCount(PackageCount packageCount) {
        if (StringUtils.isEmpty(packageCount.getMemberId())) {
            return AjaxResult.error("用户不能为空");
        }
        if (StringUtils.isEmpty(packageCount.getType())) {
            return AjaxResult.error("配置类型不能为空");
        }
        try {
            memberBizService.savePackageCountBiz(packageCount);
            return AjaxResult.success();
        } catch (Exception e) {
            return AjaxResult.error("保存配置异常");
        }
    }
}
